package com.joseph.test;

import java.util.Observable;
import java.util.Observer;

/**
 * @description
 * @author Joseph_Mok
 * @date 2016年3月17日下午3:36:44
 */
public class Reader implements Observer {

	private String readerName;

	public Reader(String readerName) {
		this.readerName = readerName;
	}

	@Override
	public void update(Observable o, Object arg) {
		Writer writer = (Writer) o;
		System.out.println(readerName + "知道" + writer.getWriterName() + "发布了新书《" + writer.getBookName() + "》");
	}
	
	public void subscribe(String writerName) {
		PublishOffice.getInstance().getWriter(writerName).addObserver(this);
		System.out.println(readerName + "订阅了" + writerName);
	}

}
